package com.android.phoenix.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.android.phoenix.R;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class MyInfo2Activity extends BaseActivity {

	private String user_data[][] = new String[][] { { "昵称: ", "1234567" },
			{ "性别: ", "男" }, { "年龄: ", "21" }, { "身高: ", "177" },
			{ "体重: ", "68kg" } };
	private int pic = R.drawable.icon_jump;

	private ListView userInfoListView = null;
	private ImageView userInfoImageView = null;
	private List<Map<String, String>> userInfoList = new ArrayList<Map<String, String>>();
	private SimpleAdapter simpleAdapter = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.acti_myinfo);

		this.userInfoListView = (ListView) findViewById(R.id.userinfo_list);
		this.userInfoImageView = (ImageView) findViewById(R.id.userinfo_set);
		for (int x = 0; x < this.user_data.length; x++) {
			Map<String, String> userInfoMap = new HashMap<String, String>();
			userInfoMap.put("userinfo_title", this.user_data[x][0]);
			userInfoMap.put("userinfo_content", this.user_data[x][1]);
			userInfoMap.put("userinfo_pic", String.valueOf(pic));
			userInfoList.add(userInfoMap);
		}
		this.simpleAdapter = new SimpleAdapter(this, this.userInfoList,
				R.layout.acti_myinfo_list, new String[] { "userinfo_title",
						"userinfo_content", "userinfo_pic" }, new int[] {
						R.id.userinfo_title, R.id.userinfo_content,
						R.id.userinfo_pic });
		this.userInfoListView.setAdapter(this.simpleAdapter);
		this.userInfoImageView.setOnClickListener(new setButListenerImpl());
		this.userInfoListView
				.setOnItemClickListener(new userItemListenerImpl());
	}

	/**
	 * Description:用户信息中设置的监听事件.
	 * 
	 * @author ares
	 * 
	 */
	private class setButListenerImpl implements OnClickListener {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent();
			intent.setClass(MyInfo2Activity.this, SettingsActivity.class);
			startActivity(intent);
		}
	}

	/**
	 * Description:用户信息中单个选项信息的监听事件.
	 * 
	 * @author ares
	 * 
	 */
	private class userItemListenerImpl implements OnItemClickListener {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			@SuppressWarnings("unchecked")
			Map<String, String> map = (Map) MyInfo2Activity.this.simpleAdapter
					.getItem(position);
			String userinfo_title = map.get("userinfo_title");
			String userinfo_content = map.get("userinfo_content");
			Toast.makeText(MyInfo2Activity.this, "" + userinfo_title + userinfo_content, Toast.LENGTH_LONG)
			.show();

		}

	}
}
